'title' => 'ObjectName',
];
- function isEnabled() {
+ public function isEnabled() {
global $wgSVGConverters, $wgSVGConverter;
if ( !isset( $wgSVGConverters[$wgSVGConverter] ) ) {
wfDebug( "\$wgSVGConverter is invalid, disabling SVG rendering.\n" );
return null;
}
+ /**
+ * Determines render language from image parameters
+ *
+ * @param array $params
+ * @return string
+ */
+ protected function getLanguageFromParams( array $params ) {
+ return $params['lang'] ?? $params['targetlang'] ?? 'en';
+ }
+
/**
* What language to render file in if none selected
*
* @param array &$params
* @return bool
*/
- function normaliseParams( $image, &$params ) {
- global $wgSVGMaxSize;
- if ( !parent::normaliseParams( $image, $params ) ) {
- return false;
+ public function normaliseParams( $image, &$params ) {
+ if ( parent::normaliseParams( $image, $params ) ) {
+ $params = $this->normaliseParamsInternal( $image, $params );
+ return true;
}
+
+ return false;
+ }
+
+ /**
+ * Code taken out of normaliseParams() for testability
+ *
+ * @since 1.33
+ *
+ * @param File $image
+ * @param array $params
+ * @return array Modified $params
+ */
+ protected function normaliseParamsInternal( $image, $params ) {
+ global $wgSVGMaxSize;
+
# Don't make an image bigger than wgMaxSVGSize on the smaller side
if ( $params['physicalWidth'] <= $params['physicalHeight'] ) {
if ( $params['physicalWidth'] > $wgSVGMaxSize ) {
$params['physicalWidth'] = $wgSVGMaxSize;
$params['physicalHeight'] = File::scaleHeight( $srcWidth, $srcHeight, $wgSVGMaxSize );
}
- } else {
- if ( $params['physicalHeight'] > $wgSVGMaxSize ) {
- $srcWidth = $image->getWidth( $params['page'] );
- $srcHeight = $image->getHeight( $params['page'] );
- $params['physicalWidth'] = File::scaleHeight( $srcHeight, $srcWidth, $wgSVGMaxSize );
- $params['physicalHeight'] = $wgSVGMaxSize;
- }
+ } elseif ( $params['physicalHeight'] > $wgSVGMaxSize ) {
+ $srcWidth = $image->getWidth( $params['page'] );
+ $srcHeight = $image->getHeight( $params['page'] );
+ $params['physicalWidth'] = File::scaleHeight( $srcHeight, $srcWidth, $wgSVGMaxSize );
+ $params['physicalHeight'] = $wgSVGMaxSize;
+ }
+ // To prevent the proliferation of thumbnails in languages not present in SVGs, unless
+ // explicitly forced by user.
+ if ( isset( $params['targetlang'] ) && !$image->getMatchedLanguage( $params['targetlang'] ) ) {
+ unset( $params['targetlang'] );
}
- return true;
+ return $params;
}
/**
$clientHeight = $params['height'];
$physicalWidth = $params['physicalWidth'];
$physicalHeight = $params['physicalHeight'];
- $lang = $params['lang'] ?? $this->getDefaultRenderLanguage( $image );
+ $lang = $this->getLanguageFromParams( $params );
if ( $flags & self::TRANSFORM_LATER ) {
return new ThumbnailImage( $image, $dstUrl, $dstPath, $params );
}
}
- function getThumbType( $ext, $mime, $params = null ) {
+ public function getThumbType( $ext, $mime, $params = null ) {
return [ 'png', 'image/png' ];
}
* @param File $file
* @return string
*/
- function getLongDesc( $file ) {
+ public function getLongDesc( $file ) {
global $wgLang;
$metadata = $this->unpackMetadata( $file->getMetadata() );
* @param string $filename
* @return string Serialised metadata
*/
- function getMetadata( $file, $filename ) {
+ public function getMetadata( $file, $filename ) {
$metadata = [ 'version' => self::SVG_METADATA_VERSION ];
try {
$metadata += SVGMetadataExtractor::getMetadata( $filename );
return 'parsed-svg';
}
- function isMetadataValid( $image, $metadata ) {
+ public function isMetadataValid( $image, $metadata ) {
$meta = $this->unpackMetadata( $metadata );
if ( $meta === false ) {
return self::METADATA_BAD;
* @param bool|IContextSource $context Context to use (optional)
* @return array|bool
*/
- function formatMetadata( $file, $context = false ) {
+ public function formatMetadata( $file, $context = false ) {
$result = [
'visible' => [],
'collapsed' => []
*/
public function makeParamString( $params ) {
$lang = '';
- if ( isset( $params['lang'] ) && $params['lang'] !== 'en' ) {
- $lang = 'lang' . strtolower( $params['lang'] ) . '-';
+ $code = $this->getLanguageFromParams( $params );
+ if ( $code !== 'en' ) {
+ $lang = 'lang' . strtolower( $code ) . '-';
}
if ( !isset( $params['width'] ) ) {
return false;
* @param array $params
* @return array
*/
- function getScriptParams( $params ) {
+ protected function getScriptParams( $params ) {
$scriptParams = [ 'width' => $params['width'] ];
if ( isset( $params['lang'] ) ) {
$scriptParams['lang'] = $params['lang'];